
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>grep、sed、awk 详解 · 日常学习笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Shell文本处理常用工具补遗.html" />
    
    
    <link rel="prev" href="Shell奇淫技巧.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"Xiechengqi","repo":"LearningNotes","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../网络学习资源整理/">
            
                <a href="../网络学习资源整理/">
            
                    
                    网络学习资源整理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../网络学习资源整理/技术学习.html">
            
                <a href="../网络学习资源整理/技术学习.html">
            
                    
                    技术学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../网络学习资源整理/运维博客.html">
            
                <a href="../网络学习资源整理/运维博客.html">
            
                    
                    运维博客
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../网络学习资源整理/工具.html">
            
                <a href="../网络学习资源整理/工具.html">
            
                    
                    工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../网络学习资源整理/静态博客模板.html">
            
                <a href="../网络学习资源整理/静态博客模板.html">
            
                    
                    静态博客模板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../网络学习资源整理/静态网站pages服务.html">
            
                <a href="../网络学习资源整理/静态网站pages服务.html">
            
                    
                    静态网站pages服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../网络学习资源整理/静态pages的CI和CD.html">
            
                <a href="../网络学习资源整理/静态pages的CI和CD.html">
            
                    
                    静态pages的CI和CD
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../网络学习资源整理/Hugo学习.html">
            
                <a href="../网络学习资源整理/Hugo学习.html">
            
                    
                    Hugo学习
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../心灵鸡汤/">
            
                <a href="../心灵鸡汤/">
            
                    
                    心灵鸡汤
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../心灵鸡汤/心灵鸡汤.html">
            
                <a href="../心灵鸡汤/心灵鸡汤.html">
            
                    
                    语录
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../Linux/">
            
                <a href="../Linux/">
            
                    
                    Linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../Linux/Linux常用命令.html">
            
                <a href="../Linux/Linux常用命令.html">
            
                    
                    Linux常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../Linux/Linux小知识.html">
            
                <a href="../Linux/Linux小知识.html">
            
                    
                    平时 linux 遇到的问题解决办法和扩展小知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Linux/Linux性能相关常用命令.html">
            
                <a href="../Linux/Linux性能相关常用命令.html">
            
                    
                    Linux性能相关常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Linux/Linux各种安装下载慢解决方法.html">
            
                <a href="../Linux/Linux各种安装下载慢解决方法.html">
            
                    
                    Linux各种安装下载慢解决方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../Linux/APT-剖析详解.html">
            
                <a href="../Linux/APT-剖析详解.html">
            
                    
                    APT 原理剖析、详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../Linux/Linux主机、虚拟机和docker网络配置.html">
            
                <a href="../Linux/Linux主机、虚拟机和docker网络配置.html">
            
                    
                    Linux 主机、虚拟机和docker网络配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../Linux/Linux文件系统学习.html">
            
                <a href="../Linux/Linux文件系统学习.html">
            
                    
                    Linux文件系统学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../Linux/Linux用户和用户组管理.html">
            
                <a href="../Linux/Linux用户和用户组管理.html">
            
                    
                    Linux用户和用户组管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../Linux/Linux用户增删改等学习.html">
            
                <a href="../Linux/Linux用户增删改等学习.html">
            
                    
                    Linux用户增删改等学习.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../Linux/Linux程序存放目录.html">
            
                <a href="../Linux/Linux程序存放目录.html">
            
                    
                    Linux程序存放目录.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="../Linux/Linux编译安装软件包详解.html">
            
                <a href="../Linux/Linux编译安装软件包详解.html">
            
                    
                    Linux C/C++ 软件包编译、安装原理详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="../Linux/SSH详解.html">
            
                <a href="../Linux/SSH详解.html">
            
                    
                    SSH 详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="../Linux/Tomcat和Ngnix和Apache.html">
            
                <a href="../Linux/Tomcat和Ngnix和Apache.html">
            
                    
                    Tomcat和Ngnix和Apache.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="../Linux/UbuntuSoftwareInstall.html">
            
                <a href="../Linux/UbuntuSoftwareInstall.html">
            
                    
                    Ubuntu 软件包安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="../Linux/YAML-配置文件语言.html">
            
                <a href="../Linux/YAML-配置文件语言.html">
            
                    
                    YAML 配置文件语言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="../Linux/bin目录详解.html">
            
                <a href="../Linux/bin目录详解.html">
            
                    
                    bin目录详解.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="../Linux/ffmpeg详解.html">
            
                <a href="../Linux/ffmpeg详解.html">
            
                    
                    ffmpeg学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="../Linux/trans命令.html">
            
                <a href="../Linux/trans命令.html">
            
                    
                    trans命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.19" data-path="../Linux/yum和rpm.html">
            
                <a href="../Linux/yum和rpm.html">
            
                    
                    Yum 和 RPM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.20" data-path="../Linux/从BashShell启动“窥探”Linux环境变量相关文件.html">
            
                <a href="../Linux/从BashShell启动“窥探”Linux环境变量相关文件.html">
            
                    
                    Linux环境变量详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.21" data-path="../Linux/新创建主机常用初始化配置.html">
            
                <a href="../Linux/新创建主机常用初始化配置.html">
            
                    
                    新建主机常用初始化配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.22" data-path="../Linux/正则表达式学习.html">
            
                <a href="../Linux/正则表达式学习.html">
            
                    
                    正则表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.23" data-path="../Linux/通过Linux开机启动项展开学习.html">
            
                <a href="../Linux/通过Linux开机启动项展开学习.html">
            
                    
                    Linux开机启动项学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.24" data-path="../Linux/防火墙学习.html">
            
                <a href="../Linux/防火墙学习.html">
            
                    
                    防火墙学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../Python/">
            
                <a href="../Python/">
            
                    
                    Python
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Python/BeautifulSoup.md">
            
                <span>
            
                    
                    Python3 BeautifulSoup 学习记录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Python/Django.html">
            
                <a href="../Python/Django.html">
            
                    
                    Python Django 学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Python/IPython使用技巧.html">
            
                <a href="../Python/IPython使用技巧.html">
            
                    
                    IPython 使用技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Python/Numpy.html">
            
                <a href="../Python/Numpy.html">
            
                    
                    Python Numpy 学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Python/Python小知识.html">
            
                <a href="../Python/Python小知识.html">
            
                    
                    Python 学习遇到的问题解决或扩展小知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../Python/Python模块管理总结.html">
            
                <a href="../Python/Python模块管理总结.html">
            
                    
                    Python 模块管理总结
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../Python/flask学习.md">
            
                <span>
            
                    
                    Flask 学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../Python/matplotlib.html">
            
                <a href="../Python/matplotlib.html">
            
                    
                    matplotlib.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="../Python/re正则表达式.html">
            
                <a href="../Python/re正则表达式.html">
            
                    
                    re正则表达式.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="../Python/图形界面学习.html">
            
                <a href="../Python/图形界面学习.html">
            
                    
                    图形界面学习.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="../Python/常用图像库学习.html">
            
                <a href="../Python/常用图像库学习.html">
            
                    
                    Python3 常用图像库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="../Python/进阶学习.html">
            
                <a href="../Python/进阶学习.html">
            
                    
                    Python3 进阶学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="./">
            
                <a href="./">
            
                    
                    Shell
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="shell小知识.html">
            
                <a href="shell小知识.html">
            
                    
                    Shell小知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="Shell奇淫技巧.html">
            
                <a href="Shell奇淫技巧.html">
            
                    
                    Shell奇淫技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.3" data-path="Linux文本操作三大利器-grep、sed、awk.html">
            
                <a href="Linux文本操作三大利器-grep、sed、awk.html">
            
                    
                    grep、sed、awk 详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="Shell文本处理常用工具补遗.html">
            
                <a href="Shell文本处理常用工具补遗.html">
            
                    
                    Shell文本处理常用工具补遗
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="句子解析.html">
            
                <a href="句子解析.html">
            
                    
                    句子解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="识别是否是root用户.html">
            
                <a href="识别是否是root用户.html">
            
                    
                    识别是否是root用户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="识别系统.html">
            
                <a href="识别系统.html">
            
                    
                    识别系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../Vim/">
            
                <a href="../Vim/">
            
                    
                    Vim
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../Vim/Vim小知识.html">
            
                <a href="../Vim/Vim小知识.html">
            
                    
                    Vim小知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../Vim/Vim编辑器再学习.html">
            
                <a href="../Vim/Vim编辑器再学习.html">
            
                    
                    Vim编辑器再学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../Vim/VimScript学习笔记.html">
            
                <a href="../Vim/VimScript学习笔记.html">
            
                    
                    VimScript 学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../Vim/YouCompleteMe安装.html">
            
                <a href="../Vim/YouCompleteMe安装.html">
            
                    
                    YouCompleteMe安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../Vim/vimrc示例1.html">
            
                <a href="../Vim/vimrc示例1.html">
            
                    
                    vimrc示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../Vim/vimrc备份.html">
            
                <a href="../Vim/vimrc备份.html">
            
                    
                    vimrc备份
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../Vim/Tmux快捷键.html">
            
                <a href="../Vim/Tmux快捷键.html">
            
                    
                    Tmux快捷键
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../Ansible/">
            
                <a href="../Ansible/">
            
                    
                    Ansible
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Ansible/术语表.html">
            
                <a href="../Ansible/术语表.html">
            
                    
                    术语表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Ansible/Ansible必知单词.html">
            
                <a href="../Ansible/Ansible必知单词.html">
            
                    
                    Ansible 常用单词
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../Ansible/Ansible学习.html">
            
                <a href="../Ansible/Ansible学习.html">
            
                    
                    Ansible 学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../Ansible/Ansible常用模板.html">
            
                <a href="../Ansible/Ansible常用模板.html">
            
                    
                    Ansible常用模板.md
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../Docker/">
            
                <a href="../Docker/">
            
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../Docker/Docker基础学习.html">
            
                <a href="../Docker/Docker基础学习.html">
            
                    
                    Docker 基础学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Docker/Docker小知识.html">
            
                <a href="../Docker/Docker小知识.html">
            
                    
                    Docker 小知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../Docker/Docker必知单词.html">
            
                <a href="../Docker/Docker必知单词.html">
            
                    
                    Docker 学习中的单词
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../Git/">
            
                <a href="../Git/">
            
                    
                    Git
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Git/git学习.html">
            
                <a href="../Git/git学习.html">
            
                    
                    Git 学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Git/git小技巧.html">
            
                <a href="../Git/git小技巧.html">
            
                    
                    Git 小技巧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../Zabbix/">
            
                <a href="../Zabbix/">
            
                    
                    Zabbix
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../Zabbix/Docker安装配置Zabbix.html">
            
                <a href="../Zabbix/Docker安装配置Zabbix.html">
            
                    
                    Docker 安装配置 Zabbix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../Zabbix/术语单词.html">
            
                <a href="../Zabbix/术语单词.html">
            
                    
                    Zabbix 中常用单词
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../Zabbix/重置密码.html">
            
                <a href="../Zabbix/重置密码.html">
            
                    
                    重置 Zabbix 账户密码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../KVM/">
            
                <a href="../KVM/">
            
                    
                    KVM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../KVM/安装配置.html">
            
                <a href="../KVM/安装配置.html">
            
                    
                    常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../KVM/虚拟机网络配置.html">
            
                <a href="../KVM/虚拟机网络配置.html">
            
                    
                    Bridged 桥接模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../Mysql/">
            
                <a href="../Mysql/">
            
                    
                    Mysql
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../Mysql/Ubuntu安装Navicat.html">
            
                <a href="../Mysql/Ubuntu安装Navicat.html">
            
                    
                    Ubuntu 安装及配置 Navicat
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../Mysql/忘记root密码.html">
            
                <a href="../Mysql/忘记root密码.html">
            
                    
                    如何替换已忘记的 root 密码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../Nginx/">
            
                <a href="../Nginx/">
            
                    
                    Nginx
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../Nginx/Nginx学习笔记.html">
            
                <a href="../Nginx/Nginx学习笔记.html">
            
                    
                    Nginx 学习
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../NoClass/">
            
                <a href="../NoClass/">
            
                    
                    闲知
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../NoClass/容易读错的IT术语.html">
            
                <a href="../NoClass/容易读错的IT术语.html">
            
                    
                    容易读错的IT术语
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../NoClass/Linux-electron-tutorial.html">
            
                <a href="../NoClass/Linux-electron-tutorial.html">
            
                    
                    Linux electron 学习记录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../NoClass/MarkdownSkills.html">
            
                <a href="../NoClass/MarkdownSkills.html">
            
                    
                    记录 Markdown 的各种小技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../NoClass/RaspeberryPi.html">
            
                <a href="../NoClass/RaspeberryPi.html">
            
                    
                    使用树莓派 3B 遇到的问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.5" data-path="../NoClass/华为国产手机芯片SoC.html">
            
                <a href="../NoClass/华为国产手机芯片SoC.html">
            
                    
                    华为国产手机芯片SoC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.6" data-path="../NoClass/图片格式详解及其对比.html">
            
                <a href="../NoClass/图片格式详解及其对比.html">
            
                    
                    图片格式详解及其对比
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.7" data-path="../NoClass/计算机小知识.html">
            
                <a href="../NoClass/计算机小知识.html">
            
                    
                    记录一些计算机的小知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.8" data-path="../NoClass/诗词.html">
            
                <a href="../NoClass/诗词.html">
            
                    
                    诗词
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../OS/">
            
                <a href="../OS/">
            
                    
                    OS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.1" data-path="../OS/学习笔记.html">
            
                <a href="../OS/学习笔记.html">
            
                    
                    操作系统学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.2" data-path="../OS/术语单词.html">
            
                <a href="../OS/术语单词.html">
            
                    
                    OS 专业词语解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.3" data-path="../OS/SoCCPU.html">
            
                <a href="../OS/SoCCPU.html">
            
                    
                    SoC 与 CPU
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../Tomcat/">
            
                <a href="../Tomcat/">
            
                    
                    Tomcat
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../Tomcat/Tomcat 学习.html">
            
                <a href="../Tomcat/Tomcat 学习.html">
            
                    
                    Tomcat 学习
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../Tomcat/Tomcat学习.html">
            
                <a href="../Tomcat/Tomcat学习.html">
            
                    
                    Tomcat 学习
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../VPS/">
            
                <a href="../VPS/">
            
                    
                    VPS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.18.1" data-path="../VPS/AWS_lightsail.html">
            
                <a href="../VPS/AWS_lightsail.html">
            
                    
                    AWS LightSail
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.2" data-path="../VPS/GCP_VM实例创建和基本配置.html">
            
                <a href="../VPS/GCP_VM实例创建和基本配置.html">
            
                    
                    GCP VM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.3" data-path="../VPS/ECS和VPS等等.html">
            
                <a href="../VPS/ECS和VPS等等.html">
            
                    
                    ECS和VPS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../ComputerComposition/">
            
                <a href="../ComputerComposition/">
            
                    
                    ComputerComposition
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.19.1" data-path="../ComputerComposition/学习笔记.html">
            
                <a href="../ComputerComposition/学习笔记.html">
            
                    
                    计算机组成原理学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../ComputerNetwork/">
            
                <a href="../ComputerNetwork/">
            
                    
                    ComputerNetwork
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.20.1" data-path="../ComputerNetwork/ProWords.html">
            
                <a href="../ComputerNetwork/ProWords.html">
            
                    
                    术语单词
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20.2" data-path="../ComputerNetwork/学习笔记.html">
            
                <a href="../ComputerNetwork/学习笔记.html">
            
                    
                    计算机网络学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20.3" data-path="../ComputerNetwork/小知识.html">
            
                <a href="../ComputerNetwork/小知识.html">
            
                    
                    学习计算机网络中的小知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20.4" data-path="../NoClass/浏览器架构简析.md">
            
                <span>
            
                    
                    浏览器架构简析
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../毕业论文/">
            
                <a href="../毕业论文/">
            
                    
                    毕业论文
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.21.1" data-path="../毕业论文/开题报告.html">
            
                <a href="../毕业论文/开题报告.html">
            
                    
                    开题报告
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >grep、sed、awk 详解</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="grep&#x3001;sed&#x3001;awk-&#x8BE6;&#x89E3;"><a name="grep&#x3001;sed&#x3001;awk-&#x8BE6;&#x89E3;" class="plugin-anchor" href="#grep&#x3001;sed&#x3001;awk-&#x8BE6;&#x89E3;"><i class="fa fa-link" aria-hidden="true"></i></a>grep&#x3001;sed&#x3001;awk &#x8BE6;&#x89E3;</h1>
<ul>
<li>grep -  &#x66F4;&#x9002;&#x5408;&#x5355;&#x7EAF;&#x7684;&#x67E5;&#x627E;&#x6216;&#x5339;&#x914D;&#x6587;&#x672C;</li>
<li>sed -  &#x66F4;&#x9002;&#x5408;&#x7F16;&#x8F91;&#x5339;&#x914D;&#x5230;&#x7684;&#x6587;&#x672C;</li>
<li>awk - &#x66F4;&#x9002;&#x5408;&#x683C;&#x5F0F;&#x5316;&#x6587;&#x672C;&#xFF0C;&#x5BF9;&#x6587;&#x672C;&#x8FDB;&#x884C;&#x8F83;&#x590D;&#x6742;&#x683C;&#x5F0F;&#x5904;&#x7406;</li>
</ul>
<h1 id="grep"><a name="grep" class="plugin-anchor" href="#grep"><i class="fa fa-link" aria-hidden="true"></i></a>grep</h1>
<ul>
<li>grep - global search regular expression(RE) and print out the line - &#x5168;&#x9762;&#x641C;&#x7D22;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x5E76;&#x628A;&#x884C;&#x6253;&#x5370;&#x51FA;&#x6765;</li>
</ul>
<h1 id="sed"><a name="sed" class="plugin-anchor" href="#sed"><i class="fa fa-link" aria-hidden="true"></i></a>sed</h1>
<ul>
<li>sed - stream editor - &#x6D41;&#x7F16;&#x8F91;&#x5668;</li>
<li>&#x4E00;&#x6B21;&#x5904;&#x7406;&#x4E00;&#x884C;&#x5185;&#x5BB9;&#xFF0C;&#x5904;&#x7406;&#x65F6;&#xFF0C;&#x628A;&#x5F53;&#x524D;&#x5904;&#x7406;&#x7684;&#x884C;&#x5B58;&#x50A8;&#x5728;&#x4E34;&#x65F6;&#x7F13;&#x51B2;&#x533A;&#x4E2D;&#xFF0C;&#x79F0;&#x4E3A;&#x201C;&#x6A21;&#x5F0F;&#x7A7A;&#x95F4;&#x201D;( pattern space )&#xFF0C;&#x63A5;&#x7740;&#x7528; sed &#x547D;&#x4EE4;&#x5904;&#x7406;&#x7F13;&#x51B2;&#x533A;&#x4E2D;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x5904;&#x7406;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x628A;&#x7F13;&#x51B2;&#x533A;&#x7684;&#x5185;&#x5BB9;&#x9001;&#x5F80;&#x5C4F;&#x5E55;</li>
<li>sed &#x9ED8;&#x8BA4;&#x4E0D;&#x4F1A;&#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x6E90;&#x6587;&#x4EF6;</li>
<li>sed &#x4E0D;&#x7BA1;&#x662F;&#x5426;&#x627E;&#x5230;&#x6307;&#x5B9A;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;&#x547D;&#x4EE4;&#x9000;&#x51FA;&#x72B6;&#x6001;&#x90FD;&#x662F; 0&#xFF1B;&#x53EA;&#x6709;&#x5F53;&#x547D;&#x4EE4;&#x5B58;&#x5728;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#x65F6;&#xFF0C;sed &#x7684;&#x9000;&#x51FA;&#x72B6;&#x6001;&#x624D;&#x662F;&#x975E; 0</li>
<li>sed &#x9002;&#x5408;&#x4F7F;&#x7528; vi &#x7C7B;&#x7F16;&#x8F91;&#x5668;&#x64CD;&#x4F5C;&#x4E0D;&#x592A;&#x65B9;&#x4FBF;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x6BD4;&#x5982;&#x64CD;&#x4F5C;&#x6709;&#x6570;&#x5343;&#x884C;&#x7684;&#x6587;&#x672C;&#x548C;&#x5728; shell &#x811A;&#x672C;&#x4E2D;&#x4FEE;&#x6539;&#x6587;&#x672C;&#x6587;&#x4EF6;</li>
<li><p><kbd><strong>sed [&#x9009;&#x9879;] &apos;&#x547D;&#x4EE4;&apos; &#x6587;&#x4EF6;&#x540D;&gt;</strong></kbd></p>
</li>
<li><p><kbd><strong>[&#x9009;&#x9879;]</strong></kbd></p>
<ul>
<li><kbd>-n</kbd> - &#x53D6;&#x6D88;&#x9ED8;&#x8BA4;&#x8F93;&#x51FA; ( sed &#x9ED8;&#x8BA4;&#x4F1A;&#x6253;&#x5370;&#x6A21;&#x5F0F;&#x7A7A;&#x95F4;&#x91CC;&#x7684;&#x5185;&#x5BB9; )</li>
<li><kbd>-e</kbd> - &#x591A;&#x70B9;&#x7F16;&#x8F91;&#xFF0C;&#x53EF;&#x4EE5;&#x6267;&#x884C;&#x591A;&#x4E2A;&#x5B50;&#x547D;&#x4EE4;&#xFF0C;&#x6BCF;&#x4E2A; <code>-e</code> &#x540E;&#x90FD;&#x53EF;&#x4EE5;&#x63A5;&#x4E00;&#x4E2A; &apos;&#x547D;&#x4EE4;&apos;</li>
<li><kbd>-f</kbd> - &#x4ECE;&#x811A;&#x672C;&#x6587;&#x4EF6;&#x4E2D;&#x8BFB;&#x53D6;&#x547D;&#x4EE4;&#xFF08; sed &#x64CD;&#x4F5C;&#x53EF;&#x4EE5;&#x4E8B;&#x5148;&#x5199;&#x5165;&#x811A;&#x672C;&#xFF0C;&#x7136;&#x540E;&#x901A;&#x8FC7; <code>-f</code> &#x8BFB;&#x53D6;&#x5E76;&#x6267;&#x884C;&#xFF09;</li>
<li><kbd>-r</kbd> - &#x5728; &apos;&#x547D;&#x4EE4;&apos; &#x4E2D;&#x5141;&#x8BB8;&#x4F7F;&#x7528;&#x6269;&#x5C55;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x5141;&#x8BB8;&#x57FA;&#x7840;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;</li>
<li><kbd>-i</kbd> - &#x76F4;&#x63A5;&#x7F16;&#x8F91;&#x539F;&#x6587;&#x4EF6;&#xFF0C;&#x4E14;&#x4E0D;&#x8F93;&#x51FA;&#x5230;&#x7EC8;&#x7AEF;</li>
</ul>
</li>
<li><kbd><strong>&apos;&#x547D;&#x4EE4;&apos;</strong></kbd><ul>
<li><kbd>a \</kbd> -  append - &#x5728;&#x5F53;&#x524D;&#x884C;&#x540E;&#x6DFB;&#x52A0;&#x4E00;&#x884C;&#x6216;&#x591A;&#x884C;&#x3002;&#x591A;&#x884C;&#x65F6;&#x9664;&#x6700;&#x540E;&#x4E00;&#x884C;&#x5916;&#xFF0C;&#x6BCF;&#x884C;&#x672B;&#x5C3E;&#x9700;&#x7528;<code>\</code>&#x7EED;&#x884C;</li>
<li><kbd>c \</kbd> - chang - &#x7528; <code>c</code> &#x540E;&#x7684;&#x65B0;&#x6587;&#x672C;&#x66FF;&#x6362;&#x6307;&#x5B9A;&#x884C;&#x3002;&#x591A;&#x884C;&#x65F6;&#x9664;&#x6700;&#x540E;&#x4E00;&#x884C;&#x5916;&#xFF0C;&#x6BCF;&#x884C;&#x672B;&#x5C3E;&#x9700;&#x7528; <code>\</code>&#x7EED;&#x884C;</li>
<li><kbd>i \</kbd> - insert -  &#x5728;&#x5F53;&#x524D;&#x884C;&#x4E4B;&#x524D;&#x63D2;&#x5165;&#x4E00;&#x884C;&#x6216;&#x591A;&#x884C;&#x3002;&#x591A;&#x884C;&#x65F6;&#x9664;&#x6700;&#x540E;&#x4E00;&#x884C;&#x5916;&#xFF0C;&#x6BCF;&#x884C;&#x672B;&#x5C3E;&#x9700;&#x7528; <code>\</code> &#x7EED;&#x884C;</li>
<li><kbd>d</kbd> - delete - &#x5220;&#x9664;&#x9009;&#x4E2D;&#x7684;&#x884C;</li>
<li><kbd>p</kbd> - print - &#x6253;&#x5370;&#x5F53;&#x524D;&#x9009;&#x62E9;&#x7684;&#x884C;</li>
<li><kbd>s/re/string/[flag]</kbd> -  subs - &#x7528; string &#x66FF;&#x6362;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F; re</li>
</ul>
</li>
</ul>
<h3 id="&#x5E38;&#x7528;&#x547D;&#x4EE4;"><a name="&#x5E38;&#x7528;&#x547D;&#x4EE4;" class="plugin-anchor" href="#&#x5E38;&#x7528;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5E38;&#x7528;&#x547D;&#x4EE4;</h3>
<blockquote>
<ul>
<li><code>sed -n</code> &#x4FEE;&#x6539;&#x884C;&#x540E;&#x4E0D;&#x4F1A;&#x6709;&#x8F93;&#x51FA;&#xFF0C;&#x6240;&#x4EE5;&#x60F3;&#x67E5;&#x770B;&#x7ED3;&#x679C;&#xFF0C;&#x4E00;&#x822C;&#x4F1A;&#x7528; <code>sed -n -e &apos;&#x64CD;&#x4F5C;&apos; -e &apos;1,$p&apos; filename</code></li>
<li><code>$</code> - &#x884C;&#x5C3E;&#x5B9A;&#x4F4D;&#x7B26;</li>
</ul>
</blockquote>
<h4 id="&#x5BF9;&#x6307;&#x5B9A;&#x7684;-nm-&#x884C;&#x64CD;&#x4F5C;"><a name="&#x5BF9;&#x6307;&#x5B9A;&#x7684;-nm-&#x884C;&#x64CD;&#x4F5C;" class="plugin-anchor" href="#&#x5BF9;&#x6307;&#x5B9A;&#x7684;-nm-&#x884C;&#x64CD;&#x4F5C;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5BF9;&#x6307;&#x5B9A;&#x7684; n~m &#x884C;&#x64CD;&#x4F5C;</h4>
<ul>
<li>&#x663E;&#x793A; n~m &#x884C;<ul>
<li><code>sed -n &apos;n,mp&apos; filename</code></li>
</ul>
</li>
<li>&#x65B0;&#x589E;&#x884C;<ul>
<li>&#x7B2C; n &#x884C;&#x540E;&#x65B0;&#x589E;&#x5B57;&#x7B26;&#x4E32; string&#xFF1A;<code>sed &apos;na string&apos; filename</code></li>
<li>&#x7B2C; n &#x884C;&#x524D;&#x65B0;&#x589E;&#x5B57;&#x7B26;&#x4E32; string&#xFF1A;<code>sed &apos;ni string&apos; filename</code></li>
<li>&#x9700;&#x8981;&#x65B0;&#x589E;&#x591A;&#x884C;&#xFF0C;&#x65B0;&#x589E;&#x884C;&#x672B;&#x5C3E;&#x52A0; <code>\</code>&#xFF0C;&#x518D;&#x6362;&#x884C;&#x8F93;&#x5165;&#x4E0B;&#x4E00;&#x65B0;&#x589E;&#x884C;&#x5373;&#x53EF;</li>
</ul>
</li>
<li>&#x5220;&#x9664; n~m &#x884C;<ul>
<li><code>sed &apos;n,md&apos; filename</code></li>
<li><code>sed &apos;n,$d&apos; filename</code> - &#x5220;&#x9664;&#x4ECE;&#x7B2C; n &#x884C;&#x5F00;&#x59CB;&#x5230;&#x7ED3;&#x675F;&#x6240;&#x6709;&#x884C;&#xFF0C;<code>$</code> &#x4EE3;&#x8868;&#x6700;&#x540E;&#x4E00;&#x884C;</li>
<li><code>sed &apos;n&apos; filename</code> - &#x5220;&#x9664;&#x7B2C; n &#x884C;&#x5355;&#x884C;</li>
</ul>
</li>
<li>&#x66FF;&#x6362; n~m &#x884C;<ul>
<li><code>sed &apos;n,mc newstring&apos; filename</code> - &#x7528; newstring &#x66FF;&#x6362;&#x7B2C; n~m &#x884C;</li>
</ul>
</li>
</ul>
<h4 id="&#x5BF9;&#x5339;&#x914D;-string-&#x7684;&#x884C;&#x64CD;&#x4F5C;"><a name="&#x5BF9;&#x5339;&#x914D;-string-&#x7684;&#x884C;&#x64CD;&#x4F5C;" class="plugin-anchor" href="#&#x5BF9;&#x5339;&#x914D;-string-&#x7684;&#x884C;&#x64CD;&#x4F5C;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5BF9;&#x5339;&#x914D; string &#x7684;&#x884C;&#x64CD;&#x4F5C;</h4>
<blockquote>
<ul>
<li>&#x5728;&#x6307;&#x5B9A; n~m &#x884C;&#x5185;&#x64CD;&#x4F5C;&#x5339;&#x914D; string &#x7684;&#x884C;&#xFF1A;<code>sed -n -e &apos;[&#x4F4D;&#x7F6E;&#x53C2;&#x6570;] &#x64CD;&#x4F5C;&#x547D;&#x4EE4;&apos; -e &apos;1,$ p&apos;  filename</code><ul>
<li>eg: <code>sed -n -e &apos;2,3 s/old/new/g&apos; -e &apos;1,$ p&apos; inputfile</code></li>
</ul>
</li>
</ul>
</blockquote>
<ul>
<li>&#x663E;&#x793A;&#x5339;&#x914D; string &#x7684;&#x884C;<ul>
<li><code>sed -n &apos;/string/p&apos; filename</code></li>
</ul>
</li>
<li>&#x5220;&#x9664;&#x5339;&#x914D; string &#x7684;&#x884C;<ul>
<li><code>sed -n &apos;/string/d&apos; filename</code></li>
</ul>
</li>
<li>&#x5728;&#x5339;&#x914D; string &#x7684;&#x884C;&#x540E;&#x63D2;&#x5165;&#x5B57;&#x7B26;&#x4E32; new<ul>
<li><code>sed -n &apos;/string/a new&apos; filename</code></li>
</ul>
</li>
<li>&#x5728;&#x5339;&#x914D; string &#x7684;&#x884C;&#x524D;&#x63D2;&#x5165;&#x5B57;&#x7B26;&#x521B; new<ul>
<li><code>sed -n &apos;/string/i new&apos; filename</code></li>
</ul>
</li>
<li>&#x7528; new &#x5B57;&#x7B26;&#x4E32;&#x66FF;&#x6362; string &#x5B57;&#x7B26;&#x4E32;<ul>
<li><code>sed &apos;[&#x4F4D;&#x7F6E;&#x53C2;&#x6570;] s/string/new/[&#x66FF;&#x6362;&#x6807;&#x5FD7;]&apos;</code></li>
<li>[&#x66FF;&#x6362;&#x6807;&#x5FD7;] - &#x6807;&#x5FD7;&#x53EF;&#x4EE5;&#x4E00;&#x8D77;&#x4F7F;&#x7528;&#xFF0C;&#x6BD4;&#x5982; <code>2p</code> &#x5C31;&#x662F;&#x66FF;&#x6362;&#x6BCF;&#x884C;&#x7B2C; 2 &#x4E2A;&#x5339;&#x914D;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5E76;&#x6253;&#x5370;&#x4FEE;&#x6539;&#x8FC7;&#x7684;&#x884C;<ul>
<li><kbd>g</kbd> - &#x5168;&#x5C40;&#x66FF;&#x6362;&#xFF0C;&#x4F1A;&#x66FF;&#x6362;&#x6587;&#x672C;&#x884C;&#x4E2D;&#x6240;&#x6709;&#x5339;&#x914D;&#x7684;&#x5B57;&#x7B26;&#x4E32;<ul>
<li>eg: <code>ps aux | sed -n -e &apos;1,10 s/0/1/g&apos; -e &apos;1,10 p&apos;</code></li>
</ul>
</li>
<li><kbd>n</kbd> ( &#x6570;&#x5B57; ) - &#x66FF;&#x6362;&#x6BCF;&#x884C;&#x4E2D;&#x7B2C; n &#x4E2A;&#x5339;&#x914D;&#x7684;&#x5B57;&#x7B26;&#x4E32;<ul>
<li>eg: <code>ps aux | sed -n -e &apos;1,10 s/0/1/2&apos; -e &apos;1,10 p&apos;</code></li>
</ul>
</li>
<li><kbd>p</kbd> - &#x66FF;&#x6362;&#x7B2C;&#x4E00;&#x4E2A;&#x5339;&#x914D;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5E76;&#x6253;&#x5370;&#x4FEE;&#x6539;&#x8FC7;&#x7684;&#x884C;<ul>
<li>eg: <code>ps aux | sed -n -e &apos;1,10 s/0/1/p&apos; -e &apos;1,10 p&apos;</code></li>
</ul>
</li>
<li><kbd>w file</kbd> - &#x66FF;&#x6362;&#x6BCF;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x5339;&#x914D;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5E76;&#x5C06;&#x6240;&#x9009;&#x7684;&#x884C;&#x5199;&#x5165;&#x6587;&#x4EF6; file &#x4E2D;<ul>
<li>eg: <code>ps aux | sed -n -e &apos;1,10 s/0/1/w test&apos; -e &apos;1,10 p&apos;</code></li>
</ul>
</li>
<li><kbd>&#x7F3A;&#x7701;</kbd> - &#x9ED8;&#x8BA4;&#x66FF;&#x6362;&#x6BCF;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x5339;&#x914D;&#x7684;&#x5B57;&#x7B26;&#x4E32;<ul>
<li>eg: <code>ps aux | sed -n -e &apos;1,10 s/0/1/&apos; -e &apos;1,10 p&apos;</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>&#x5BF9;&#x5339;&#x914D; string &#x884C;&#x6267;&#x884C;&#x81EA;&#x5B9A;&#x4E49;&#x547D;&#x4EE4;<ul>
<li><code>sed -n &apos;[&#x4F4D;&#x7F6E;&#x53C2;&#x6570;] s/string/{&#x547D;&#x4EE4;}&apos; filename</code></li>
</ul>
</li>
</ul>
<h3 id="&#x5B9E;&#x6218;&#x547D;&#x4EE4;"><a name="&#x5B9E;&#x6218;&#x547D;&#x4EE4;" class="plugin-anchor" href="#&#x5B9E;&#x6218;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9E;&#x6218;&#x547D;&#x4EE4;</h3>
<pre><code class="lang-shell"># &#x5220;&#x9664;&#x7A7A;&#x884C;&#x5E76;&#x8F93;&#x51FA;
$ sed &apos;/^$/d&apos; file 
&#x6216;
$ sed -n &apos;/./p&apos; file
# &#x5220;&#x9664;&#x9996;&#x884C;&#x7A7A;&#x683C;
$ sed &apos;s/^[[ :space: ]]*//g&apos; file
# &#x5728;&#x7279;&#x5B9A;&#x5B57;&#x7B26;&#x4E32;&#x540E;&#x6DFB;&#x6362;&#x884C;
$ sed &apos;s/new/&amp;\n/g&apos; file
# &#x5728;&#x7279;&#x5B9A;&#x5B57;&#x7B26;&#x4E32;&#x524D;&#x6DFB;&#x52A0;&#x7A7A;&#x884C;
$ sed &apos;s/new/\n&amp;/g&apos; file
</code></pre>
<h1 id="awk"><a name="awk" class="plugin-anchor" href="#awk"><i class="fa fa-link" aria-hidden="true"></i></a>awk</h1>
<h2 id="&#x629B;&#x7816;&#x5F15;&#x7389;"><a name="&#x629B;&#x7816;&#x5F15;&#x7389;" class="plugin-anchor" href="#&#x629B;&#x7816;&#x5F15;&#x7389;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x629B;&#x7816;&#x5F15;&#x7389;</h2>
<p><kbd><strong>&#x5982;&#x4F55;&#x67E5;&#x770B;Linux&#x7CFB;&#x7EDF;&#x4E0A;&#x7684;&#x6240;&#x6709;&#x7528;&#x6237;&#xFF1F;</strong></kbd></p>
<pre><code class="lang-bash">awk <span class="hljs-string">&apos;BEGIN{
    FS=&quot;:&quot;
    printf(&quot;%-10s%-20s\n&quot;, &quot;UserName&quot;, &quot;HomeDir&quot;)
    print &quot;==============================&quot;
}
{
    printf(&quot;%-10s%-20s\n&quot;, $1, $6)
}
END{
    print &quot;==============================&quot;
    printf(&quot;User(s):%d\n&quot;, NR)
    print &quot;==============================&quot;
}&apos;</span> /etc/passwd
</code></pre>
<h2 id="&#x539F;&#x7406;&#x7B80;&#x8FF0;"><a name="&#x539F;&#x7406;&#x7B80;&#x8FF0;" class="plugin-anchor" href="#&#x539F;&#x7406;&#x7B80;&#x8FF0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x539F;&#x7406;&#x7B80;&#x8FF0;</h2>
<div align="center">
<img src="images/awk_theory.png"><br>awk &#x539F;&#x7406;
</div>



<p>&#x4ECE;&#x4E0A;&#x56FE;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#xFF0C;awk &#x5728;&#x5DE5;&#x4F5C;&#x65F6;&#x4E3B;&#x8981;&#x5206;&#x4E3A;&#x4EE5;&#x4E0B;&#x4E09;&#x4E2A;&#x90E8;&#x5206;&#xFF1A;</p>
<ul>
<li><p><code>BEGIN</code> - &#x4E5F;&#x5C31;&#x662F;&#x6240;&#x8C13;&#x7684;&#x521D;&#x59CB;&#x5316;&#x6A21;&#x5757;&#xFF0C;&#x6BD4;&#x5982;&#x5B9A;&#x4E49;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E9B;&#x503C;&#x7B49;&#xFF0C;&#x5B83;&#x4F1A;&#x5728;&#x6570;&#x636E;&#x5904;&#x7406;&#x90E8;&#x5206;&#x6267;&#x884C;&#x4E4B;&#x524D;&#x6267;&#x884C;&#xFF0C;&#x5E76;&#x4E14;&#x53EA;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF0C;&#x8FD9;&#x4E00;&#x90E8;&#x5206;&#x662F;&#x53EF;&#x9009;&#x7684;</p>
</li>
<li><p><code>&#x6570;&#x636E;&#x5904;&#x7406;</code> - &#x8FD9;&#x4E00;&#x90E8;&#x5206;&#x4E5F;&#x5C31;&#x662F; awk &#x811A;&#x672C;&#x7684;&#x6838;&#x5FC3;&#x90E8;&#x5206;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x5BF9;&#x4EE5;&#x6A21;&#x5F0F; <code>pattern</code> &#x4E0E;&#x5927;&#x62EC;&#x53F7;&#x62EC;&#x8D77;&#x6765;&#x7684;&#x64CD;&#x4F5C; <code>action</code> &#x7EC4;&#x5408;&#x800C;&#x6210;&#x7684;&#xFF0C;&#x4E8C;&#x8005;&#x53EF;&#x80FD;&#x4F1A;&#x51FA;&#x73B0;&#x4EE5;&#x4E0B;&#x7EC4;&#x5408;&#xFF1A;</p>
<ul>
<li><kdb>pattern {action}&lt;/kbd&gt; - &#x8BB0;&#x5F55;&#x5339;&#x914D;&#x5BF9;&#x5E94;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;&#x5219;&#x6267;&#x884C;&#x5927;&#x62EC;&#x53F7;&#x4E2D;&#x7684;&#x64CD;&#x4F5C;</kdb></li>
<li><kdb>pattern&lt;/kbd&gt; - &#x8BB0;&#x5F55;&#x5339;&#x914D;&#x5BF9;&#x5E94;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;&#x5219;&#x76F4;&#x63A5;&#x6253;&#x5370;&#x8BB0;&#x5F55;</kdb></li>
<li><kdb>{action}&lt;/kbd&gt; - &#x5BF9;&#x6BCF;&#x4E00;&#x6761;&#x8BB0;&#x5F55;&#x90FD;&#x6267;&#x884C;&#x5927;&#x62EC;&#x53F7;&#x4E2D;&#x7684;&#x64CD;&#x4F5C;</kdb></li>
</ul>
<p>&#x6570;&#x636E;&#x5904;&#x7406;&#x6A21;&#x5757;&#x4F1A;&#x5FAA;&#x73AF;&#x8BFB;&#x53D6;&#x5F85;&#x5904;&#x7406;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x8BB0;&#x5F55;&#xFF0C;&#x6BCF;&#x6B21;&#x8BFB;&#x53D6;&#x4E00;&#x6761;&#x8BB0;&#x5F55;&#xFF0C;&#x5904;&#x7406;&#x5B8C;&#x4E00;&#x6761;&#x4EE5;&#x540E;&#x518D;&#x8BFB;&#x53D6;&#x4E0B;&#x4E00;&#x6761;&#x8BB0;&#x5F55;&#xFF0C;&#x76F4;&#x81F3;&#x6240;&#x6709;&#x8BB0;&#x5F55;&#x88AB;&#x8BFB;&#x53D6;&#x5B8C;&#x6BD5;</p>
</li>
<li><p><code>END</code> - &#x662F;&#x6700;&#x7EC8;&#x7684;&#x6536;&#x5C3E;&#x5904;&#x7406;&#x6A21;&#x5757;&#xFF0C;&#x5B83;&#x4F1A;&#x5728;&#x6240;&#x6709;&#x6570;&#x636E;&#x5904;&#x7406;&#x5B8C;&#x6210;&#x4EE5;&#x540E;&#x624D;&#x6267;&#x884C;&#xFF0C;&#x5E76;&#x4E14;&#x53EA;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF1B;&#x6BD4;&#x5982;&#x6211;&#x4EEC;&#x5904;&#x7406;&#x5B8C;&#x6570;&#x636E;&#x4E86;&#xFF0C;&#x9700;&#x8981;&#x8F93;&#x51FA;&#x4E00;&#x5171;&#x5904;&#x7406;&#x4E86;&#x591A;&#x5C11;&#x6761;&#x8BB0;&#x5F55;&#xFF0C;&#x591A;&#x5C11;&#x4E2A;&#x5B57;&#x6BB5;&#x7B49;&#x4FE1;&#x606F;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5728; END &#x90E8;&#x5206;&#x8FDB;&#x884C;&#x8F93;&#x51FA;&#xFF0C;&#x8FD9;&#x4E00;&#x90E8;&#x5206;&#x4E5F;&#x662F;&#x53EF;&#x9009;&#x7684;</p>
</li>
</ul>
<blockquote>
<ul>
<li>&#x8BB0;&#x5F55; - &#x884C;</li>
<li>&#x5B57;&#x6BB5; - &#x5217;</li>
</ul>
</blockquote>
<h2 id="&#x547D;&#x4EE4;&#x4F7F;&#x7528;"><a name="&#x547D;&#x4EE4;&#x4F7F;&#x7528;" class="plugin-anchor" href="#&#x547D;&#x4EE4;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x547D;&#x4EE4;&#x4F7F;&#x7528;</h2>
<ul>
<li>awk &#x662F;&#x4E00;&#x79CD;&#x5904;&#x7406;&#x6587;&#x672C;&#x6587;&#x4EF6;&#x7684;&#x8BED;&#x8A00;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x5F3A;&#x5927;&#x7684;&#x6587;&#x672C;&#x5206;&#x6790;&#x5DE5;&#x5177;</li>
<li>awk &#x66F4;&#x9002;&#x5408;&#x683C;&#x5F0F;&#x5316;&#x6587;&#x672C;&#xFF0C;&#x5BF9;&#x6587;&#x672C;&#x8FDB;&#x884C;&#x8F83;&#x590D;&#x6742;&#x683C;&#x5F0F;&#x5904;&#x7406;</li>
<li>awk &#x662F;&#x4EE5;&#x5217;&#x4E3A;&#x5212;&#x5206;&#x8BA1;&#x6570;&#x7684;&#xFF0C;$0 &#x8868;&#x793A;&#x5F53;&#x524D;&#x884C;&#xFF08;&#x5373;&#x6240;&#x6709;&#x5217;&#xFF09;&#xFF0C;$1 &#x8868;&#x793A;&#x7B2C;&#x4E00;&#x5217;&#xFF0C;$2 &#x8868;&#x793A;&#x7B2C;&#x4E8C;&#x5217;</li>
<li><kbd><strong>awk [&#x9009;&#x9879;] &apos;[&#x52A8;&#x4F5C;]&apos; [&#x6587;&#x4EF6;&#x540D;]</strong></kbd></li>
<li>awk &#x52A8;&#x4F5C;&#x53EA;&#x80FD;&#x4F7F;&#x7528;&#x5355;&#x5F15;&#x53F7;</li>
<li><kbd><strong>[&#x9009;&#x9879;]</strong> </kbd></li>
</ul>
<table>
<thead>
<tr>
<th>&#x9009;&#x9879;</th>
<th>&#x89E3;&#x91CA;</th>
</tr>
</thead>
<tbody>
<tr>
<td>-F fs</td>
<td>&#x5212;&#x5206;&#x6570;&#x636E;&#x5B57;&#x6BB5;&#x7684;&#x5206;&#x9694;&#x7B26;</td>
</tr>
<tr>
<td>-f file</td>
<td>&#x4ECE;&#x6307;&#x5B9A;&#x6587;&#x4EF6;&#x4E2D;&#x8BFB;&#x53D6; awk &#x547D;&#x4EE4;</td>
</tr>
<tr>
<td>-v var=value</td>
</tr>
</tbody>
</table>
<h3 id="awk-printf-&#x683C;&#x5F0F;&#x8BF4;&#x660E;&#x7B26;"><a name="awk-printf-&#x683C;&#x5F0F;&#x8BF4;&#x660E;&#x7B26;" class="plugin-anchor" href="#awk-printf-&#x683C;&#x5F0F;&#x8BF4;&#x660E;&#x7B26;"><i class="fa fa-link" aria-hidden="true"></i></a>awk printf &#x683C;&#x5F0F;&#x8BF4;&#x660E;&#x7B26;</h3>
<ul>
<li><kbd><strong>awk [&#x9009;&#x9879;] &apos;{printf &quot;%&#x8BF4;&#x660E;&#x7B26;1,%&#x8BF4;&#x660E;&#x7B26;2&quot;,var1&#xFF0C;var2}&apos; &#x6587;&#x4EF6;&#x540D;</strong></kbd></li>
<li><code>%&#x8BF4;&#x660E;&#x7B26;</code> - <kbd><strong>%[flags][width][.precision]conversion</strong></kbd></li>
</ul>
<p><kbd><strong>%</strong></kbd> - &#x662F;&#x5FC5;&#x987B;&#x7684;, &#x4EFB;&#x4F55;&#x683C;&#x5F0F;&#x7B26;&#x90FD;&#x7531;&#x767E;&#x5206;&#x53F7;&#x5F00;&#x59CB;</p>
<p><kbd><strong>flag &#x6807;&#x5FD7;&#xFF08;&#x53EF;&#x7701;&#xFF09;</strong></kbd></p>
<table>
<thead>
<tr>
<th>flag</th>
<th>&#x89E3;&#x91CA;</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#x9ED8;&#x8BA4;</td>
<td>&#x53F3;&#x5BF9;&#x9F50;&#xFF0C;&#x4E14;&#x7528;&#x7A7A;&#x683C;&#x586B;&#x5145;</td>
</tr>
<tr>
<td>-</td>
<td>&#x5DE6;&#x5BF9;&#x9F50;</td>
</tr>
<tr>
<td>+</td>
<td>&#x6253;&#x5370;&#x6B63;&#x8D1F;&#x6570;&#x7684;&#x7B26;&#x53F7;</td>
</tr>
<tr>
<td>0</td>
<td>&#x7528; 0 &#x586B;&#x5145;</td>
</tr>
</tbody>
</table>
<p><kbd><strong>width &#x5BBD;&#x5EA6;&#xFF08;&#x53EF;&#x7701;&#xFF09;</strong></kbd> - &#x8F93;&#x51FA;&#x7684;&#x5BBD;&#x5EA6;</p>
<p><kbd><strong>precision &#x7CBE;&#x5EA6;&#xFF08;&#x53EF;&#x7701;&#xFF09;</strong></kbd></p>
<table>
<thead>
<tr>
<th>awk &apos;{printf &quot;%.5&#x8BF4;&#x660E;&#x7B26;\n&quot;,$1}&apos;</th>
<th>&#x89E3;&#x91CA;</th>
</tr>
</thead>
<tbody>
<tr>
<td>%d,%i,%o,%u,%x,%X</td>
<td>&#x6570;&#x5B57;&#x4F4D;&#x6570;&#x6700;&#x5927;&#x4E3A; 5&#xFF0C;&#x4E0D;&#x591F;&#x524D;&#x7F00;&#x8865; 0</td>
</tr>
<tr>
<td>%e, %E</td>
<td>&#x6570;&#x5B57;&#x4F4D;&#x6570;&#x6700;&#x5927;&#x4E3A; 5&#xFF0C;&#x4E0D;&#x591F;&#x540E;&#x7F00;&#x8865; 0</td>
</tr>
<tr>
<td>%f</td>
<td>&#x5982;&#x679C;&#x5C0F;&#x6570;&#x70B9;&#x540E;&#x4F4D;&#x6570;&#x5C11;&#x4E8E; 5&#xFF0C;&#x540E;&#x7F00;&#x8865; 0</td>
</tr>
<tr>
<td>%g, %G</td>
<td>&#x6700;&#x591A;&#x6570;&#x5B57;&#x4F4D;&#x6570;</td>
</tr>
<tr>
<td>%s</td>
<td>&#x5B57;&#x7B26;&#x4F4D;&#x6570;&#x5C11;&#x4E8E; 5&#xFF0C;&#x539F;&#x6837;&#x8F93;&#x51FA;&#xFF0C;&#x591A;&#x4E8E;5&#xFF0C;&#x53EA;&#x8F93;&#x51FA;&#x524D; 5 &#x4E2A;&#x5B57;&#x7B26;</td>
</tr>
</tbody>
</table>
<p><kbd><strong>conversion &#x8BF4;&#x660E;&#x7B26;&#xFF08;&#x5FC5;&#x9009;&#xFF09;</strong></kbd></p>
<table>
<thead>
<tr>
<th>conversion &#x8BF4;&#x660E;&#x7B26;</th>
<th>&#x89E3;&#x91CA;</th>
</tr>
</thead>
<tbody>
<tr>
<td>%d &#x548C; %i</td>
<td>&#x5341;&#x8FDB;&#x5236;&#x7684;&#x6574;&#x6570;&#x90E8;&#x5206;</td>
</tr>
<tr>
<td>%s</td>
<td>&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>%f</td>
<td>&#x6D6E;&#x70B9;&#x6570;</td>
</tr>
<tr>
<td>%c</td>
<td>&#x5355;&#x4E2A;&#x5B57;&#x7B26;</td>
</tr>
<tr>
<td>%e &#x6216; %E</td>
<td>&#x79D1;&#x5B66;&#x8BA1;&#x6570;&#x6CD5;&#x683C;&#x5F0F;</td>
</tr>
<tr>
<td>%o</td>
<td>&#x516B;&#x8FDB;&#x5236;&#x6570;</td>
</tr>
<tr>
<td>%x</td>
<td>&#x5341;&#x516D;&#x8FDB;&#x5236;&#x6570;</td>
</tr>
<tr>
<td>%%</td>
<td>%</td>
</tr>
</tbody>
</table>
<h4 id="&#x5B9E;&#x4F8B;&#x89E3;&#x6790;"><a name="&#x5B9E;&#x4F8B;&#x89E3;&#x6790;" class="plugin-anchor" href="#&#x5B9E;&#x4F8B;&#x89E3;&#x6790;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9E;&#x4F8B;&#x89E3;&#x6790;</h4>
<p><kbd>%-5.2f</kbd> - &#x8F93;&#x51FA;&#x603B;&#x5BBD;&#x5EA6;&#x4E3A; 5 &#x7684;&#x6D6E;&#x70B9;&#x6570;&#xFF0C;&#x5176;&#x4E2D;&#x5C0F;&#x6570;&#x4F4D;&#x4E3A; 2&#xFF0C;&#x6574;&#x6570;&#x4F4D;&#x4E3A; 2&#xFF0C;&#x5C0F;&#x6570;&#x70B9;&#x5360; 1 &#x4F4D;&#xFF0C;&#x4E0D;&#x591F; 5 &#x4E3A;&#x5DE6;&#x5BF9;&#x9F50;</p>
<p><kbd>%9.2f</kbd> -  &#x8868;&#x793A;&#x8F93;&#x51FA;&#x573A;&#x5BBD;&#x4E3A;9&#x7684;&#x6D6E;&#x70B9;&#x6570;, &#x5176;&#x4E2D;&#x5C0F;&#x6570;&#x4F4D;&#x4E3A; 2&#xFF0C; &#x6574;&#x6570;&#x4F4D;&#x4E3A; 6&#xFF0C;&#x5C0F;&#x6570;&#x70B9;&#x5360; 1 &#x4F4D;, &#x4E0D;&#x591F; 9 &#x4F4D;&#x53F3;&#x5BF9;&#x9F50;</p>
<p><kbd>%04d</kbd> - &#x8868;&#x793A;&#x5728;&#x8F93;&#x51FA;&#x4E00;&#x4E2A;&#x5C0F;&#x4E8E; 4 &#x4F4D;&#x7684;&#x6570;&#x503C;&#x65F6;, &#x5C06;&#x5728;&#x524D;&#x9762;&#x8865; 0 &#x4F7F;&#x5176;&#x603B;&#x5BBD;&#x5EA6;&#x4E3A; 4 &#x4F4D;</p>
<p><kbd>%6.9s</kbd> - &#x8868;&#x793A;&#x663E;&#x793A;&#x4E00;&#x4E2A;&#x957F;&#x5EA6;&#x4E0D;&#x5C0F;&#x4E8E; 6 &#x4E14;&#x4E0D;&#x5927;&#x4E8E; 9 &#x7684;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x82E5;&#x5927;&#x4E8E; 9, &#x5219;&#x7B2C; 9 &#x4E2A;&#x5B57;&#x7B26;&#x4EE5;&#x540E;&#x7684;&#x5185;&#x5BB9;&#x5C06;&#x88AB;&#x5220;&#x9664;</p>
<h3 id="awk-&#x5185;&#x7F6E;&#x53D8;&#x91CF;"><a name="awk-&#x5185;&#x7F6E;&#x53D8;&#x91CF;" class="plugin-anchor" href="#awk-&#x5185;&#x7F6E;&#x53D8;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>awk &#x5185;&#x7F6E;&#x53D8;&#x91CF;</h3>
<ul>
<li><p><code>NF</code>&#xFF1A;&#x8868;&#x793A;&#x5F53;&#x524D;&#x884C;&#x7684;&#x5B57;&#x6BB5;&#x603B;&#x6570;</p>
<ul>
<li><code>NF</code> - &#x6253;&#x5370;&#x5F53;&#x524D;&#x884C;&#x5B57;&#x6BB5;&#x6570;</li>
<li><code>$NF</code> - &#x6253;&#x5370;&#x5F53;&#x524D;&#x884C;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;</li>
<li><code>$NF-1</code> - &#x6253;&#x5370;&#x5F53;&#x524D;&#x884C;&#x5012;&#x6570;&#x7B2C;&#x4E8C;&#x4E2A;&#x5B57;&#x6BB5;</li>
</ul>
</li>
<li><p><code>NR</code>&#xFF1A;&#x8868;&#x793A;&#x5F53;&#x524D;&#x5904;&#x7406;&#x7684;&#x662F;&#x7B2C;&#x51E0;&#x884C;</p>
</li>
<li><p><code>FILENAME</code>&#xFF1A;&#x5F53;&#x524D;&#x6587;&#x4EF6;&#x540D;</p>
</li>
<li><code>FS</code>&#xFF1A;&#x5B57;&#x6BB5;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x7A7A;&#x683C;&#x548C;&#x5236;&#x8868;&#x7B26;&#x3002;</li>
<li><code>RS</code>&#xFF1A;&#x884C;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x7528;&#x4E8E;&#x5206;&#x5272;&#x6BCF;&#x4E00;&#x884C;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x6362;&#x884C;&#x7B26;&#x3002;</li>
<li><code>OFS</code>&#xFF1A;&#x8F93;&#x51FA;&#x5B57;&#x6BB5;&#x7684;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x7528;&#x4E8E;&#x6253;&#x5370;&#x65F6;&#x5206;&#x9694;&#x5B57;&#x6BB5;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#x7A7A;&#x683C;&#x3002;</li>
<li><code>ORS</code>&#xFF1A;&#x8F93;&#x51FA;&#x8BB0;&#x5F55;&#x7684;&#x5206;&#x9694;&#x7B26;&#xFF0C;&#x7528;&#x4E8E;&#x6253;&#x5370;&#x65F6;&#x5206;&#x9694;&#x8BB0;&#x5F55;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#x6362;&#x884C;&#x7B26;&#x3002;</li>
<li><code>OFMT</code>&#xFF1A;&#x6570;&#x5B57;&#x8F93;&#x51FA;&#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A; <code>&#xFF05;.6g</code>&#x3002;</li>
</ul>
<pre><code class="lang-shell">$ cat /etc/passwd | awk -F &apos;:&apos; &apos;{printf &quot;&#x884C;&#x5B57;&#x6BB5;&#x6570;&#xFF1A;%d\n&quot;,NF}&apos;
$ cat /etc/passwd | awk -F &apos;:&apos; &apos;{printf &quot;&#x884C;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;&#x662F;&#xFF1A;%s\n&quot;, $NF}&apos;
# print &#x547D;&#x4EE4;&#x91CC;&#x9762;&#xFF0C;&#x5982;&#x679C;&#x539F;&#x6837;&#x8F93;&#x51FA;&#x5B57;&#x7B26;&#xFF0C;&#x8981;&#x653E;&#x5728;&#x53CC;&#x5F15;&#x53F7;&#x91CC;&#x9762;
$ cat /etc/passwd | awk -F &apos;:&apos; &apos;{print &quot;&#x884C;&#x5B57;&#x6BB5;&#x6570;&#xFF1A;&quot; NF}&apos;  # &#x548C;&#x4E0A;&#x9762; printf &#x6548;&#x679C;&#x4E00;&#x6837;
</code></pre>
<h3 id="awk-&#x5185;&#x7F6E;&#x51FD;&#x6570;"><a name="awk-&#x5185;&#x7F6E;&#x51FD;&#x6570;" class="plugin-anchor" href="#awk-&#x5185;&#x7F6E;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>awk &#x5185;&#x7F6E;&#x51FD;&#x6570;</h3>
<blockquote>
<ul>
<li><a href="https://www.gnu.org/software/gawk/manual/html_node/Built_002din.html#Built_002din" target="_blank">&#x5185;&#x7F6E;&#x51FD;&#x6570;&#x5B8C;&#x6574;&#x5217;&#x8868;</a></li>
</ul>
</blockquote>
<ul>
<li><p><code>toupper()</code>&#xFF1A;&#x5B57;&#x7B26;&#x8F6C;&#x4E3A;&#x5927;&#x5199;</p>
</li>
<li><p><code>tolower()</code>&#xFF1A;&#x5B57;&#x7B26;&#x8F6C;&#x4E3A;&#x5C0F;&#x5199;</p>
</li>
<li><code>length()</code>&#xFF1A;&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;</li>
<li><code>substr()</code>&#xFF1A;&#x8FD4;&#x56DE;&#x5B50;&#x5B57;&#x7B26;&#x4E32;</li>
<li><code>sin()</code>&#xFF1A;&#x6B63;&#x5F26;</li>
<li><code>cos()</code>&#xFF1A;&#x4F59;&#x5F26;</li>
<li><code>sqrt()</code>&#xFF1A;&#x5E73;&#x65B9;&#x6839;</li>
<li><code>rand()</code>&#xFF1A;&#x968F;&#x673A;&#x6570;</li>
</ul>
<pre><code class="lang-shell">$ cat /etc/passwd | head -10 | awk &apos;{print toupper($0)}&apos;
</code></pre>
<h3 id="awk-&#x6761;&#x4EF6;&#x5224;&#x65AD;"><a name="awk-&#x6761;&#x4EF6;&#x5224;&#x65AD;" class="plugin-anchor" href="#awk-&#x6761;&#x4EF6;&#x5224;&#x65AD;"><i class="fa fa-link" aria-hidden="true"></i></a>awk &#x6761;&#x4EF6;&#x5224;&#x65AD;</h3>
<ul>
<li><kbd><strong>awk [&#x9009;&#x9879;] &apos;&#x6761;&#x4EF6;&#x5224;&#x65AD; {&#x52A8;&#x4F5C;}&apos; &#x6587;&#x4EF6;&#x540D;</strong></kbd></li>
<li>&#x9002;&#x5408;&#x4E8E;&#x53EA;&#x9700;&#x4E00;&#x6B21;&#x5224;&#x65AD;</li>
<li><code>[&#x9009;&#x9879;]</code>  &#x548C; <code>&apos;&#x6761;&#x4EF6;&#x5224;&#x65AD; {&#x52A8;&#x4F5C;}&apos;</code> &#x4E4B;&#x95F4;&#x7A7A;&#x683C;&#x4E00;&#x5B9A;&#x4E0D;&#x80FD;&#x5C11;&#xFF0C;<code>&apos;&#x6761;&#x4EF6;&#x5224;&#x65AD; {&#x52A8;&#x4F5C;}&apos;</code> &#x5185;&#x90E8;&#x7A7A;&#x683C;&#x53EF;&#x4EE5;&#x7701;&#x7565;</li>
</ul>
<pre><code class="lang-shell"># &#x8F93;&#x51FA;&#x5947;&#x6570;&#x884C;
$ cat /etc/passwd | awk &apos;NR % 2 == 1 {print $0}&apos;
# &#x8F93;&#x51FA;&#x7B2C; 5 &#x884C;&#x540E;&#x7684;&#x884C;
$ cat /etc/passwd | awk &apos;NR &gt; 5 {print $0}&apos;
# &#x8F93;&#x51FA;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;&#x662F; &apos;root&apos; &#x6216; &apos;bin&apos; &#x7684;&#x884C;
$ cat /etc/passwd | awk -F &apos;:&apos; &apos;$1 == &quot;root&quot; || $1 == &quot;bin&quot; {print $0} &apos;
</code></pre>
<h4 id="awk-if-&#x6761;&#x4EF6;&#x5224;&#x65AD;"><a name="awk-if-&#x6761;&#x4EF6;&#x5224;&#x65AD;" class="plugin-anchor" href="#awk-if-&#x6761;&#x4EF6;&#x5224;&#x65AD;"><i class="fa fa-link" aria-hidden="true"></i></a>awk if &#x6761;&#x4EF6;&#x5224;&#x65AD;</h4>
<ul>
<li><kbd><strong>awk [&#x9009;&#x9879;] &apos;{if(&#x6761;&#x4EF6;&#x5224;&#x65AD;) &#x52A8;&#x4F5C;}&apos; &#x6587;&#x4EF6;&#x540D;</strong></kbd></li>
<li>&#x9002;&#x5408;&#x4E8E;&#x9700;&#x8981;&#x591A;&#x6B21;&#x5224;&#x65AD;</li>
</ul>
<pre><code class="lang-shell"># if &#x5224;&#x65AD;&#x51FA;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x6BB5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x5927;&#x4E8E; &apos;q&apos; &#x7684;&#x884C;&#xFF0C;&#x5E76;&#x8F93;&#x51FA;
$ cat /etc/passwd | awk -F &apos;:&apos; &apos;{if ($1 &gt; &quot;q&quot;) print $0}&apos;
# &#x7B49;&#x4EF7;&#x4E8E;
$ cat /etc/passwd | awk -F &apos;:&apos; &apos;$1 &gt; &quot;q&quot; {print $0}&apos;

# if else
$ cat /etc/passwd | awk -F &apos;:&apos; &apos;{if ($1 &gt; &quot;m&quot;) print $0; else print &quot;---&quot;}&apos;
</code></pre>
<h2 id="&#x53C2;&#x8003;"><a name="&#x53C2;&#x8003;" class="plugin-anchor" href="#&#x53C2;&#x8003;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x53C2;&#x8003;</h2>
<ul>
<li><a href="http://www.ruanyifeng.com/blog/2018/11/awk.html?20191114101617#comment-last" target="_blank">awk &#x5165;&#x95E8;&#x6559;&#x7A0B; - &#x962E;&#x4E00;&#x5CF0;</a></li>
<li><a href="https://www.jellythink.com/archives/138" target="_blank">&#x8FDB;&#x9636;&#xFF1A;&#x73A9;&#x73A9;awk - &#x679C;&#x51BB;&#x60F3;</a></li>
<li><a href="https://www.jellythink.com/archives/140" target="_blank">&#x8FDB;&#x9636;&#xFF1A;awk&#x4E2D;&#x7684;&#x51FD;&#x6570; - &#x679C;&#x51BB;&#x60F3;</a></li>
</ul>
<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> <a href="https://github.com/Xiechengqi" target="_blank">Xiechengqi</a> </span> &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0; <span class="page-footer-ex-footer-update"> <strong>&#x6700;&#x65B0;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;</strong> 2020-01-04 15:54:39 </span> </footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Shell奇淫技巧.html" class="navigation navigation-prev " aria-label="Previous page: Shell奇淫技巧">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Shell文本处理常用工具补遗.html" class="navigation navigation-next " aria-label="Next page: Shell文本处理常用工具补遗">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"grep、sed、awk 详解","level":"1.6.3","depth":2,"next":{"title":"Shell文本处理常用工具补遗","level":"1.6.4","depth":2,"path":"Shell/Shell文本处理常用工具补遗.md","ref":"Shell/Shell文本处理常用工具补遗.md","articles":[]},"previous":{"title":"Shell奇淫技巧","level":"1.6.2","depth":2,"path":"Shell/Shell奇淫技巧.md","ref":"Shell/Shell奇淫技巧.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","-livereload","-sharing","expandable-chapters","popup","pageview-count","code","back-to-top-button","hide-element","github-buttons","github","splitter","search-pro","anchors","page-footer-ex","advanced-emoji","sharing-plus"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/Xiechengqi/LearningNotes"},"page-footer-ex":{"copyright":"[Xiechengqi](https://github.com/Xiechengqi)","markdown":true,"update_format":"YYYY-MM-DD HH:mm:ss","update_label":"<strong>最新修订时间：</strong>"},"splitter":{},"search-pro":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"popup":{},"code":{"copyButtons":true},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"back-to-top-button":{},"pageview-count":{},"github-buttons":{"buttons":[{"user":"Xiechengqi","repo":"LearningNotes","type":"star","size":"small","count":true}]},"advanced-emoji":{"embedEmojis":false},"sharing":{"qq":false,"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{},"expandable-chapters":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"日常学习笔记","language":"zh-hans","gitbook":"*","description":"日常学习笔记"},"file":{"path":"Shell/Linux文本操作三大利器-grep、sed、awk.md","mtime":"2020-01-04T07:54:39.012Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-03-28T02:57:41.582Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

